// pages/addLesson/addLesson.js
var app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
var common = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
      imgUrls: [
          'https://api.eastfair.com/transpo/DataFile/lunbo/transpolunbo01.jpg',
          'https://api.eastfair.com/transpo/DataFile/lunbo/transpolunbo02.jpg',
          'https://api.eastfair.com/transpo/DataFile/lunbo/transpolunbo03.jpg'
      ],
      indicatorDots: true,
      autoplay: true,
      interval: 5000,
      duration: 1000,
      incolor: 'rgba(255,255,255,0.3)',
      incoloractive: '#fff',
      pageindex: 1,
      pagesize: 5,
      messageList: [],
      article_content: [],
      show: false,
      refresh: true
  },
  /**
   * 生命周期函数--监听页面加载
   */
  handbook:function (e) {
      wx.navigateTo({
          url:'../handbook/handbook?curindex=' + e.currentTarget.dataset.index
      })
  },
    business:function (e) {
       if (e.currentTarget.dataset.index == 1) {
           wx.navigateTo({
               url:'../businessman/businessman'
           })
       } else if (e.currentTarget.dataset.index == 2) {
           wx.navigateTo({
             url:'../find-exhibits/find-exhibits'
           })
       }else{
         wx.navigateTo({
           url: '../floorplan/floorplan'
         })
       }
    },
  messageList: function () {
      var that = this;
      common.ajax({
          url: 'PersonMain/GetMsgListSmallRoutine',
          data: {
              psnID:'',
              amcIDs:'',
              pageIndex:that.data.pageindex,
              pageSize: that.data.pagesize
          },
          // loading: '加载中...',
          userinfo: false,
          success: function (res) {
              that.setData({
                 show: true
              })
              if (res.data.length < that.data.pagesize) {
                  that.setData({
                      refresh: false
                  })
              } else {
                  that.data.pageindex ++
                  that.setData({
                      pageindex: that.data.pageindex
                  })
              }
              if (res.data.length > 0) {
                  for (var i=0;i<res.data.length;i++){
                      res.data[i].AMEContent = WxParse.wxParse( that.data.article_content[i], 'html', res.data[i].AMEContent, that, 1)
                  }
                  that.data.messageList = that.data.messageList.concat(res.data)
                  that.setData({
                      messageList: that.data.messageList,
                      article_content: that.data.article_content
                  })
              }
          }
      })
  },
  onLoad: function () {
      wx.setNavigationBarTitle({
          title: '首页'
      });
      this.messageList()
  },
    search:function () {
        wx.navigateTo({
            url: '../search/search'
        })
    },
    messageDetail: function (e){
        wx.navigateTo({
            url:'../newsDetail/newsDetail?AMEID=' + e.currentTarget.dataset.t
        })
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
      this.setData({
          refresh: true,
          pagesize: 10,
          pageindex:1,
          messageList: []
      });
      this.messageList();
      wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
      var that = this;
      if (that.data.refresh) {
          that.messageList()
      }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})